<?php

namespace App\Service\User;

use App\Constants\ErrorCode;
use App\Model\User;
use App\Model\UserFollow;
use App\Service\BaseService;

/**
 * 用户关注（取消）
 */
class UserFollowService extends BaseService
{
    public function handle()
    {
        $userId = $this->getUserId();
        $profileUserId = $this->request->input('profile_user_id', 0);
        $op = $this->request->input('op', 1);
        if ($userId == $profileUserId) {
            return $this->setError(ErrorCode::PARAMETER_ERROR, '无法关注自己哦！');
        }
        if (!$profileUserId || !User::getUser($profileUserId)) {
            return $this->setError(ErrorCode::PARAMETER_ERROR);
        }

        //添加（取消）关注
        UserFollow::addFollow($userId, $profileUserId, $op);
        return ['result' => 1];
    }
}
